package jp.dodododo.dao.dialect;

import java.sql.ResultSet;
import java.text.SimpleDateFormat;
import java.util.Date;

import jp.dodododo.dao.paging.LimitOffset;

public class Standard implements Dialect {
	public String limitOffsetSql(String originalSQL, LimitOffset limitOffset) {
		long offset = limitOffset.getOffset();
		long limit = limitOffset.getLimit();
		StringBuilder sqlBuf = new StringBuilder(originalSQL);
		sqlBuf.append(" LIMIT ");
		sqlBuf.append(limit);
		sqlBuf.append(" OFFSET ");
		sqlBuf.append(offset);
		return sqlBuf.toString();
	}

	public String sequenceNextValSql(String sequenceName) {
		throw new UnsupportedOperationException();
	}

	public String identitySelectSql() {
		throw new UnsupportedOperationException();
	}

	public String getSuffix() {
		throw new UnsupportedOperationException();
	}

	public ResultSet resultSet(ResultSet rs) {
		return rs;
	}

	public String toDateString(Date date) {
		SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
		return "'" + sdf.format(date) + "'";
	}

	public String toTimestampString(Date date) {
		SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH.mm.ss");
		return "'" + sdf.format(date) + "'";
	}
}
